home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / Miro_Installer.exe / xulrunner / python / theme.py < prev    next >
Encoding:
Python Source  |  2008-01-10  |  6.4 KB  |  143 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. from gtcache import gettext as _
  19. import logging
  20. import config
  21. import prefs
  22. import app
  23. import views
  24. import indexes
  25. import os
  26. from eventloop import asUrgent
  27. from database import DDBObject
  28. import opml
  29. import iconcache
  30. import resources
  31. import platform
  32. import guide
  33. import feed
  34. import folder
  35. import playlist
  36.  
  37. class ThemeHistory(DDBObject):
  38.     def __init__(self):
  39.         DDBObject.__init__(self)
  40.         self.lastTheme = None
  41.         self.pastThemes = []
  42.         self.theme = config.get(prefs.THEME_NAME)
  43.         if self.theme is not None:
  44.             self.theme = unicode(self.theme)
  45.         # if we don't have a theme, self.theme will be None
  46.         self.pastThemes.append(self.theme)
  47.         self.onFirstRun()
  48.  
  49.     # We used to do this on restore, but we need to make sure that the
  50.     # whole database is loaded because we're checking to see if objects
  51.     # are present.  So, we call it when we access the object in app.py
  52.     def checkNewTheme(self):
  53.         self.theme = config.get(prefs.THEME_NAME)
  54.         if self.theme is not None:
  55.             self.theme = unicode(self.theme)
  56.         if self.theme not in self.pastThemes:
  57.             self.pastThemes.append(self.theme)
  58.             self.onFirstRun()
  59.         if self.lastTheme != self.theme:
  60.             self.lastTheme = self.theme
  61.             self.onThemeChange()
  62.  
  63.     @asUrgent
  64.     def onThemeChange(self):
  65.         self.signalChange()
  66.  
  67.     def onFirstRun(self):
  68.         logging.info("Spawning Miro Guide...")
  69.         guideURL = unicode(config.get(prefs.CHANNEL_GUIDE_URL))
  70.         if guide.getGuideByURL(guideURL) is None:
  71.             guide.ChannelGuide(guideURL,
  72.             unicode(config.get(prefs.CHANNEL_GUIDE_ALLOWED_URLS)).split())
  73.  
  74.         if config.get(prefs.MAXIMIZE_ON_FIRST_RUN).lower() not in ['false','no','0']:
  75.             app.delegate.maximizeWindow()
  76.         if self.theme is not None: # we have a theme
  77.             new_guides = unicode(config.get(prefs.ADDITIONAL_CHANNEL_GUIDES)).split()
  78.             for temp_guide in new_guides:
  79.                 if guide.getGuideByURL(temp_guide) is None:
  80.                     guide.ChannelGuide(temp_guide)
  81.             if ((config.get(prefs.DEFAULT_CHANNELS_FILE) is not None) and
  82.                 (config.get(prefs.THEME_NAME) is not None) and 
  83.                 (config.get(prefs.THEME_DIRECTORY) is not None)):
  84.                 importer = opml.Importer()
  85.                 filepath = os.path.join(
  86.                     config.get(prefs.THEME_DIRECTORY),
  87.                     config.get(prefs.THEME_NAME),
  88.                     config.get(prefs.DEFAULT_CHANNELS_FILE))
  89.                 importer.importSubscriptionsFrom(filepath,
  90.                                                  showSummary = False)
  91.             elif None not in self.pastThemes:
  92.                 # We pretend to have run the default theme, and then
  93.                 # install the default channels.  XXX: If Miro Guide isn't
  94.                 # installed by the theme and it doesn't provide a default
  95.                 # set of channels, we'll never install the Miro Guide.
  96.  
  97.                 # This code would install the Miro Guide if it isn't
  98.                 # already installed
  99.                 # if guide.getGuideByURL(prefs.CHANNEL_GUIDE_URL.default) is None:
  100.                 #     guide.ChannelGuide(prefs.CHANNEL_GUIDE_URL.default)
  101.                 self.pastThemes.append(None)
  102.                 self._installDefaultFeeds()
  103.         else: # no theme
  104.             self._installDefaultFeeds()
  105.  
  106.     @asUrgent
  107.     def _installDefaultFeeds(self):
  108.         initialFeeds = resources.path("initial-feeds.democracy")
  109.         if os.path.exists(initialFeeds):
  110.             urls = subscription.parseFile(initialFeeds)
  111.             if urls is not None:
  112.                 for url in urls:
  113.                     feed.Feed(url, initiallyAutoDownloadable=False)
  114.             dialog = dialogs.MessageBoxDialog(_("Custom Channels"), Template(_("You are running a version of $longAppName with a custom set of channels.")).substitute(longAppName=config.get(prefs.LONG_APP_NAME)))
  115.             dialog.run()
  116.             app.controller.initial_feeds = True
  117.         else:
  118.             logging.info("Adding default feeds")
  119.             if platform.system() == 'Darwin':
  120.                 defaultFeedURLs = [u'http://www.getmiro.com/screencasts/mac/mac.feed.rss']
  121.             elif platform.system() == 'Windows':
  122.                 defaultFeedURLs = [u'http://www.getmiro.com/screencasts/windows/win.feed.rss']
  123.             else:
  124.                 defaultFeedURLs = [u'http://www.getmiro.com/screencasts/windows/win.feed.rss']
  125.             defaultFeedURLs.extend([ (_('Starter Channels'),
  126.                                       [u'http://richie-b.blip.tv/posts/?skin=rss',
  127.                                        u'http://feeds.pbs.org/pbs/kcet/wiredscience-video',
  128.                                        u'http://www.jpl.nasa.gov/multimedia/rss/podfeed-hd.xml',
  129.                                        u'http://www.linktv.org/rss/hq/mosaic.xml']),
  130.                                    ])
  131.  
  132.             for default in defaultFeedURLs:
  133.                 print repr(default)
  134.                 if isinstance(default, tuple): # folder
  135.                     defaultFolder = default
  136.                     c_folder = folder.ChannelFolder(defaultFolder[0])
  137.                     for url in defaultFolder[1]:
  138.                         d_feed = feed.Feed(url, initiallyAutoDownloadable=False)
  139.                         d_feed.setFolder(c_folder)
  140.                 else: # feed
  141.                     d_feed = feed.Feed(default, initiallyAutoDownloadable=False)
  142.             playlist.SavedPlaylist(_(u"Example Playlist"))
  143.